import request from "@/utils/request";
import { AxiosPromise } from "axios";
import qs from "qs";
import {
  GroupActivityQuery,
  GroupActivityePageResult,
  SkuQuery,
  SkuPageResult,
  GroupTypeForm,
} from "./types";

/**
 * 获取拼团列表
 *
 * @param queryParams
 */
export function getGroupActivityPage(
  queryParams: GroupActivityQuery
): AxiosPromise<GroupActivityePageResult> {
  return request({
    url: "/api/v1/activity/group/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取sku选品列表
 *
 * @param queryParams
 */
export function getSkuList(queryParams: SkuQuery): AxiosPromise<SkuPageResult> {
  return request({
    url: "/api/v1/prod/page",
    method: "get",
    params: queryParams,
  });
}

/**
 * 根据sku ids 获取sku列表
 *
 * @param ids
 */
export function getSkuInfoListByIds(
  ids: number[]
): AxiosPromise<SkuPageResult> {
  return request({
    url: "/api/v1/sku/info",
    method: "get",
    params: {
      skuIds: ids,
    },
    paramsSerializer: (params) => {
      return qs.stringify(params, {
        indices: false,
      });
    },
  });
}

/**
 * 新增拼团活动
 *
 * @param data
 */
export function addGroupActivity(data: GroupTypeForm) {
  return request({
    url: "/api/v1/activity/group",
    method: "post",
    data: data,
  });
}

/**
 * 根据id获取当前编辑的活动信息的接口
 *
 * @param id
 */
export function getGroupInfoById(id: number): AxiosPromise<GroupTypeForm> {
  return request({
    url: `/api/v1/activity/group/${id}`,
    method: "get",
  });
}

/**
 * 编辑拼团活动接口
 *
 * @param data
 */
export function updateGroupActivity(data: GroupTypeForm) {
  return request({
    url: "/api/v1/activity/group",
    method: "put",
    data: data,
  });
}
